from Page.page1 import Page1
from Page.Page2 import Page2
from Page.Page3 import Page3
from selenium import webdriver
from selenium.webdriver.common.by import By
import unittest,time
class TestCase(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Edge()
        self.driver.maximize_window()
    def tearDown(self):
        self.driver.quit()
    def test_customer_01(self):
        po = Page1(self.driver)
        po.open_url('http://localhost:8080')
        self.driver.implicitly_wait(10)
        po.login()
        po.username()
        po.password()
        po.loginbtn()
        po.sure()
        time.sleep(2)
        po.accept()
        time.sleep(2)
        dy1 = self.driver.find_element(By.XPATH, '/html/body/div[1]/div/section/section/main/div[2]/span[1]').text
        print(dy1)
        dytext1 = dy1.split(' ')[1]
        print(dytext1)
        po.add()
        po.name()
        po.gsname()
        po.contact()
        po.email()
        po.phone()
        po.queren()
        time.sleep(3)
        #断言总条数加1
        dy = self.driver.find_element(By.XPATH,'/html/body/div[1]/div/section/section/main/div[2]/span[1]').text
        print(dy)
        dytext = dy.split(' ')[1]
        print(dytext)
        self.assertEqual((int(dytext1)+1),int(dytext))
    def test_customer_02(self):
        po = Page2(self.driver)
        po.open_url('http://localhost:8080')
        self.driver.implicitly_wait(10)
        po.login()
        po.username()
        po.password()
        po.loginbtn()
        po.sure()
        time.sleep(2)
        po.accept()
        time.sleep(2)
        dy1 = self.driver.find_element(By.XPATH, '/html/body/div[1]/div/section/section/main/div[2]/span[1]').text
        print(dy1)
        dytext1 = dy1.split(' ')[1]
        print(dytext1)
        po.dele()
        time.sleep(2)
        po.accept()
        time.sleep(2)
        po.accept()
        time.sleep(3)
        #断言总条数-1
        self.driver.refresh()
        dy = self.driver.find_element(By.XPATH,'/html/body/div[1]/div/section/section/main/div[2]/span[1]').text
        print(dy)
        dytext = dy.split(' ')[1]
        print(dytext)
        self.assertEqual((int(dytext1)-1),int(dytext))

    def test_customer_03(self):
        po = Page3(self.driver)
        po.open_url('http://localhost:8080')
        self.driver.implicitly_wait(10)
        po.login()
        po.username()
        po.password()
        po.loginbtn()
        po.sure()
        time.sleep(2)
        po.accept()
        time.sleep(2)
        po.input()
        time.sleep(2)
        po.search()
        time.sleep(2)
        dy = self.driver.find_element(By.XPATH, '/html/body/div[1]/div/section/section/main/div[2]/span[1]').text
        print(dy)
        dytext = dy.split(' ')[1]
        print(dytext)
        self.assertEqual( 1, int(dytext))


if __name__ == '__main__':
    unittest.main()